package rsa

import (
	"strings"
)

const (
	pkcs1PriPemBegin = "-----BEGIN RSA PRIVATE KEY-----\n"
	pkcs1PriPemEnd   = "\n-----END RSA PRIVATE KEY-----"
	pkcs1PubPemBegin = "-----BEGIN RSA PUBLIC KEY-----\n"
	pkcs1PubPemEnd   = "\n-----END RSA PUBLIC KEY-----"
)

func formatPkcs1PrivateKey(key string) string {
	if !strings.HasPrefix(key, pkcs1PriPemBegin) {
		key = pkcs1PriPemBegin + key
	}
	if !strings.HasSuffix(key, pkcs1PriPemEnd) {
		key = key + pkcs1PriPemEnd
	}
	return key
}

func formatPkcs1PublicKey(key string) string {
	if !strings.HasPrefix(key, pkcs1PubPemBegin) {
		key = pkcs1PubPemBegin + key
	}
	if !strings.HasSuffix(key, pkcs1PubPemEnd) {
		key = key + pkcs1PubPemEnd
	}
	return key
}
